package hanjia;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/15-下午11:09
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode53 {

    public int maxSubArray(int[] nums) {

        if (nums.length==1){
            return nums[0];
        }

        int[] dp = new int[nums.length];
        dp[0]=nums[0];
        int result=dp[0];


        for (int i=1;i<nums.length;i++){
            dp[i]=Math.max(dp[i-1]+nums[i],nums[i]);
            result=Math.max(result,dp[i]);
        }
        return result;


    }
}
